package com.shuoyue.ycgk.ui.estimate;

import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.BaseMvpActivity;
import com.shuoyue.ycgk.entity.EstimateHis;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.utils.SpacesItemDecoration;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class EstimateHisActivity extends BaseMvpActivity<EstimateHisContract.Presenter>
        implements EstimateHisContract.View {

    @BindView(R.id.page_title)
    TextView pageTitle;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.refreshlayout)
    SmartRefreshLayout refreshlayout;

    EstimateHisAdapter esAdapter;
    int subjectTypeid;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_sigle_list;
    }

    @Override
    protected void initView() {
        pageTitle.setText("估分历史");
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.addItemDecoration(new SpacesItemDecoration(SizeUtil.dip2px(mContext, 12), false));

        esAdapter = new EstimateHisAdapter(null);
        recyclerView.setAdapter(esAdapter);
        refreshlayout.setEnableLoadMore(false);

        refreshlayout.setOnRefreshListener(refreshLayout -> {
            mPresenter.getEsListHis(subjectTypeid);
            refreshLayout.finishRefresh();
        });

        registEmptyView(esAdapter);
        esAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            EstimateHis estimateHis = (EstimateHis) adapter.getItem(position);
            switch (view.getId()) {
                case R.id.lay_all:

                    break;

                case R.id.button:
                    EsSourtActivity.start(mContext, estimateHis.getEvaId(), estimateHis.getTestId(),estimateHis.getTitle());
                    break;
            }
        });
    }

    @Override
    public void initData() {
        subjectTypeid = getIntent().getIntExtra("id",-1);
        super.initData();
        mPresenter = new EstimateHisContract.Presenter();//.Presenter();
        mPresenter.attachView(this);
        mPresenter.getEsListHis(subjectTypeid);
    }


    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void getEsListHisSuc(List<EstimateHis> list) {
        esAdapter.resetData(list);
    }
}
